package com.ruoyi.web.controller.wx;

import cn.hutool.core.util.URLUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信数据回调接口
 *
 * @author LANIAKEA
 * @version 1.0
 * @date 2024/11/14
 */
@RestController
@RequestMapping("/callback")

public class CallbackController {

    String sToken = "akaja";
    String sCorpID = "ww07d10d36fac3d386";
    String sEncodingAESKey = "RCzz2Obda3tzwcoofcItNtvOcL05B1aF0oJfswgWvTl";

    /**
     * 数据回调URL
     *
     * @return
     */
    @PostMapping("/data")
    public String callbackData() {
        return "success";
    }

    @GetMapping({"/data","/cmd"})
    public String callbackData(String msg_signature,
                                   String timestamp, String nonce,
                                   String echostr) {
        msg_signature = URLUtil.decode(msg_signature);
        echostr = URLUtil.decode(echostr);
        //输出所有参数



        System.out.println("msg_signature:" + msg_signature);
        System.out.println("timestamp:" + timestamp);
        System.out.println("nonce:" + nonce);
        System.out.println("echostr:" + echostr);

        String sEchoStr = ""; //需要返回的明文
        try {
            //WXBizJsonMsgCrypt wxcpt = new WXBizJsonMsgCrypt(sToken, sEncodingAESKey, sCorpID);
            //
            //sEchoStr = wxcpt.VerifyURL(msg_signature, timestamp,
            //        nonce, echostr);
            System.out.println("verifyurl echostr: " + sEchoStr);


            // 验证URL成功，将sEchoStr返回
            // HttpUtils.SetResponse(sEchoStr);
        } catch (Exception e) {
            //验证URL失败，错误原因请查看异常
            e.printStackTrace();
        }


        return sEchoStr;
    }


}
